package num268;

import java.util.Arrays;
import java.util.HashMap;

/**
 * 268. 丢失的数字
 * 题目：https://leetcode-cn.com/problems/missing-number/
 * 三叶姐题解:  * 三叶姐题解: https://leetcode-cn.com/problems/ugly-number/solution/gong-shui-san-xie-jian-dan-de-fen-qing-k-dlvg/
 *
 * 数组哈希
 */
class Solution2 {
    public int missingNumber(int[] nums) {
        int n = nums.length;
        boolean[] hash = new boolean[n + 1];
        for (int i = 0; i < n; i++) {
            hash[nums[i]] = true;
        }
        for (int i = 0; i < n; i++) {
            if (!hash[i]) return i;
        }
        return n;
    }

    public static void main(String[] args) {
        new Solution2().missingNumber(new int[]{3, 0, 2});
    }
}
